package com.ydkj.a37e_mall.Classes.Acitivity.BaseActivity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.baidu.navisdk.adapter.BNOuterLogUtil;
import com.baidu.navisdk.adapter.BNOuterTTSPlayerCallback;
import com.baidu.navisdk.adapter.BNRoutePlanNode;
import com.baidu.navisdk.adapter.BaiduNaviManager;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.ydkj.a37e_mall.Classes.Applicatiom.MyApplication;
import com.ydkj.a37e_mall.Classes.Model.Request.GetBusinessReq;
import com.ydkj.a37e_mall.Classes.Model.Request.UpdataStore;
import com.ydkj.a37e_mall.Classes.Model.Response.GetBusinessResp;
import com.ydkj.a37e_mall.R;
import com.ydkj.a37e_mall.Resource.Utils.Async_http_get;
import com.ydkj.a37e_mall.Resource.Utils.CommonUtil;
import com.ydkj.a37e_mall.Resource.Utils.Const;
import com.ydkj.a37e_mall.Resource.Utils.GsonImpl;
import com.ydkj.a37e_mall.Resource.Utils.SharedPreferencesUtil;
import com.ydkj.a37e_mall.Resource.View.CustomProgressDialog;
import com.ydkj.a37e_mall.Resource.View.StatusBarUtil;

import org.json.JSONObject;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.onekeyshare.OnekeyShare;
import cz.msebera.android.httpclient.Header;

import static com.baidu.navisdk.adapter.PackageUtil.getSdcardDir;

/**
 * Created by Administrator on 2017/1/18.
 * <p>
 * 我的业务
 */

public class MyBusinessActivity extends BaseActivity implements View.OnClickListener {
    Activity mActivity;
    private MyApplication myApplication;
    private SharedPreferencesUtil sharedPreferencesUtil;
    private ImageView img_back;
    private TextView tv_mybusiness_review, tv_mybusiness_tb, tv_mybusiness_passed, tv_mybusiness_close;
    private PullToRefreshListView ptflv_mybusiness_result;
    private MyBusinessAdapter myBusinessAdapter;
    private List<GetBusinessResp.ResultEntity.DataEntity> mybusinesslist;
    private List<String> integerList;
    private PopupWindow pop_phone;
    private PopupWindow pop_examine;
    private LinearLayout lly_pop_phone;
    private TextView tv_pop_phone, tv_pop_cancel;
    private String mSDCardPath = null;
    private static final String APP_FOLDER_NAME = "BNSDKDemo";
    public static final String ROUTE_PLAN_NODE = "routePlanNode";
    private String authinfo = null;
    private int code; //判断pop是初审通过（1） 申请关闭（2）


    private static final int LOAD = 0;// 加载
    private static final int REFRESH = 1;// 刷新
    private static final int MORE = 2;// 更多

    @Override

    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my_business);
        mActivity = this;
        BNOuterLogUtil.setLogSwitcher(true);//
        if (initDirs()) {
            Log.e("ssss", "initNavi");
            initNavi();
        }
        init();
//        initWindow();
    }

    private void initWindow() {
        StatusBarUtil.setColor(mActivity, getResources().getColor(R.color.A000000), 0);

    }

    private void init() {
        myApplication = MyApplication.getInstance();
        sharedPreferencesUtil = SharedPreferencesUtil.getInstance(mActivity);
        img_back = (ImageView) mActivity.findViewById(R.id.img_back);
        img_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        tv_mybusiness_review = (TextView) mActivity.findViewById(R.id.tv_mybusiness_review);
        tv_mybusiness_tb = (TextView) mActivity.findViewById(R.id.tv_mybusiness_tb);
        tv_mybusiness_passed = (TextView) mActivity.findViewById(R.id.tv_mybusiness_passed);
        tv_mybusiness_close = (TextView) mActivity.findViewById(R.id.tv_mybusiness_close);

        integerList = new ArrayList<>();
        GetBusinessList(REFRESH);
        mybusinesslist = new ArrayList<>();

        ptflv_mybusiness_result = (PullToRefreshListView) mActivity.findViewById(R.id.ptflv_mybusiness_result);
        ptflv_mybusiness_result.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
        myBusinessAdapter = new MyBusinessAdapter(mybusinesslist);
        ptflv_mybusiness_result.setAdapter(myBusinessAdapter);
        ptflv_mybusiness_result.setOnRefreshListener2(new PullToRefreshBase.OnRefreshListener2<ListView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
                GetBusinessList(REFRESH);
            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
                GetBusinessList(MORE);

            }
        });


        tv_mybusiness_review.setOnClickListener(this);
        tv_mybusiness_tb.setOnClickListener(this);
        tv_mybusiness_passed.setOnClickListener(this);
        tv_mybusiness_close.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        WindowManager.LayoutParams lp;

        switch (view.getId()) {
            case R.id.tv_mybusiness_review://商户审核
                break;
            case R.id.tv_mybusiness_tb://工资通宝
                startActivity(new Intent(mActivity, WagesTbActivity.class));
                break;
            case R.id.tv_mybusiness_passed://初审通过
                integerList.clear();
                for (GetBusinessResp.ResultEntity.DataEntity dataEntity : mybusinesslist) {
                    if (dataEntity.getCheck_code() == 1) {
                        integerList.add(dataEntity.getId());
                    }
                }

                if (integerList.size() != 1) {
                    CommonUtil.showToast(mActivity, "请选择门店");
                    return;
                }

                code = 1;
                initShowPop();
                lp = getWindow().getAttributes();
                lp.alpha = 0.5f;
                getWindow().setAttributes(lp);
                pop_examine.showAtLocation(view, Gravity.CENTER, 0, 0);

                break;
            case R.id.tv_mybusiness_close://申请关闭
                integerList.clear();
                for (GetBusinessResp.ResultEntity.DataEntity dataEntity : mybusinesslist) {
                    if (dataEntity.getCheck_code() == 1) {
                        integerList.add(dataEntity.getId());
                    }
                }

                if (integerList.size() != 1) {
                    CommonUtil.showToast(mActivity, "请选择门店");
                    return;
                }
                code = 2;
                initShowPop();
                lp = getWindow().getAttributes();
                lp.alpha = 0.5f;
                getWindow().setAttributes(lp);
                pop_examine.showAtLocation(view, Gravity.CENTER, 0, 0);
                break;
        }
    }

    private void GetBusinessList(final int type) {
        CustomProgressDialog.createDialog(mActivity).show();
        GetBusinessReq req = new GetBusinessReq();
        req.setUuid(myApplication.getDataEntity().getUuid());
        req.setType("2");

        if (type == LOAD || type == REFRESH) {
            page = 1;
        } else {
            page = mybusinesslist.size() / 10 + 1;
        }
        req.setPage(page + "");

        req.setPage_size("10");

        RequestParams params = new RequestParams();
        params.put("token", sharedPreferencesUtil.getAccessToken());
        params.put("secret", req.getSecret());
        Async_http_get.get(Const.COMMON_ADDRESS + req.urlString(), params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);
                CustomProgressDialog.Dismiss();
                ptflv_mybusiness_result.onRefreshComplete();
                String errno = response.optString("errno");
                String errmsg = response.optString("errmsg");
                if (errno.equals("000")) {
                    GetBusinessResp resp = GsonImpl.get().toObject(response.toString(), GetBusinessResp.class);

                    if (type == LOAD || type == REFRESH) {
                        mybusinesslist.clear();
                        mybusinesslist.addAll(resp.getResult().getData());
                    } else {
                        mybusinesslist.addAll(resp.getResult().getData());
                    }
                    if (mybusinesslist.size() % 10 > 0) {
                        ptflv_mybusiness_result.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
                    } else {
                        ptflv_mybusiness_result.setMode(PullToRefreshBase.Mode.BOTH);
                    }
                    myBusinessAdapter.notifyDataSetChanged();
                    ptflv_mybusiness_result.onRefreshComplete();
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
            }
        });
    }


    //修改门店状态
    private void UpdataStore(String stats) {
        CustomProgressDialog.createDialog(mActivity).show();
        UpdataStore req = new UpdataStore();
        req.setUuid(myApplication.getDataEntity().getUuid());
        req.setStats(stats);

        RequestParams params = new RequestParams();
        params.put("token", sharedPreferencesUtil.getAccessToken());
        params.put("secret", req.getSecret());

        AsyncHttpClient httpClient = new AsyncHttpClient();
        httpClient.put(Const.COMMON_ADDRESS + req.urlString() + integerList.get(0), params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);
                CustomProgressDialog.Dismiss();
                String errno = response.optString("errno");
                String errmsg = response.optString("errmsg");
                if (errno.equals("000")) {
                    CommonUtil.showToast(mActivity, errmsg);
                    pop_examine.dismiss();
                    GetBusinessList(REFRESH);

                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
                CustomProgressDialog.Dismiss();
                CommonUtil.showToast(mActivity, "网络连接失败");
            }
        });
    }

    private class MyBusinessAdapter extends BaseAdapter {
        private List<GetBusinessResp.ResultEntity.DataEntity> searchListList;

        private MyBusinessAdapter(List<GetBusinessResp.ResultEntity.DataEntity> info) {
            if (info == null) {
                info = new ArrayList<>();
            }
            searchListList = info;
        }

        @Override
        public int getCount() {
            return searchListList.size();
        }

        @Override
        public GetBusinessResp.ResultEntity.DataEntity getItem(int position) {
            return searchListList.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup viewGroup) {
            ViewHolder vh = null;
            if (convertView == null) {
                convertView = LayoutInflater.from(mActivity).inflate(R.layout.mybusiness_listview_list, null);
                vh = new ViewHolder();
                vh.img_search = (ImageView) convertView.findViewById(R.id.img_search);
                vh.img_examine_select = (ImageView) convertView.findViewById(R.id.img_examine_select);
                vh.tv_search_name = (TextView) convertView.findViewById(R.id.tv_search_name);
                vh.tv_search_address = (TextView) convertView.findViewById(R.id.tv_search_address);
                vh.tv__search_distance = (TextView) convertView.findViewById(R.id.tv__search_distance);
                vh.divide = (TextView) convertView.findViewById(R.id.divide1);
                vh.lly_search_phone = (LinearLayout) convertView.findViewById(R.id.lly_search_phone);
                vh.lly_search_gps = (LinearLayout) convertView.findViewById(R.id.lly_search_gps);
                vh.lly_search_share = (LinearLayout) convertView.findViewById(R.id.lly_search_share);
                vh.lly_search = (LinearLayout) convertView.findViewById(R.id.lly_search);
                vh.lly_select = (LinearLayout) convertView.findViewById(R.id.lly_select);
            } else {
                vh = (ViewHolder) convertView.getTag();
            }
            convertView.setTag(vh);
            if (position > 0) {
                vh.divide.setVisibility(View.VISIBLE);
            }
            ImageLoader.getInstance().displayImage(getItem(position).getThumb(), vh.img_search, displayImageOptions);
            vh.tv_search_name.setText(getItem(position).getName());
            vh.tv_search_address.setText(getItem(position).getDetail());


//            if (getItem(position).getCheck_code() == 0) {
//                vh.img_examine_select.setBackground(getResources().getDrawable(R.mipmap.choose_item_defint));
//            } else if (getItem(position).getCheck_code() == 1) {
//                vh.img_examine_select.setBackground(getResources().getDrawable(R.mipmap.choose_item_red));
//            }


            vh.lly_select.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    GetBusinessResp.ResultEntity.DataEntity dataEntity = searchListList.get(position);

                    for (GetBusinessResp.ResultEntity.DataEntity dataEntitys : searchListList) {
                        if (dataEntitys.getId().equals(dataEntity.getId())) {
                            dataEntitys.setCheck_code(1);
                        } else {
                            dataEntitys.setCheck_code(0);
                        }
                    }
                    myBusinessAdapter.notifyDataSetChanged();
                }
            });

            GetBusinessResp.ResultEntity.DataEntity dataEntity = searchListList.get(position);
            if (dataEntity.getCheck_code() == 1) {
                vh.img_examine_select.setBackground(getResources().getDrawable(R.mipmap.choose_item_red));
            } else {
                vh.img_examine_select.setBackground(getResources().getDrawable(R.mipmap.choose_item_defint));

            }
            //门店详情
            vh.lly_search.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                }
            });
            //打电话
            vh.lly_search_phone.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    initPhonePopuWindow(getItem(position).getMobile());
                    pop_phone.setAnimationStyle(R.style.popupWindowAnimation);
                    pop_phone.showAtLocation(mActivity.findViewById(R.id.lly_business), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
                    pop_phone.update();
                }
            });
            //导航
            vh.lly_search_gps.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (BaiduNaviManager.isNaviInited()) {
                        routeplanToNavi(Double.parseDouble(getItem(position).getLng()), Double.parseDouble(getItem(position).getLat()), BNRoutePlanNode.CoordinateType.GCJ02);
//                        routeplanToNavi(118.161024, 24.509077, BNRoutePlanNode.CoordinateType.GCJ02);

                    }
                }
            });
            //分享
            vh.lly_search_share.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    showShare(getItem(position).getLat());
                }
            });
            return convertView;
        }

        private class ViewHolder {
            private ImageView img_search, img_examine_select;
            private TextView tv_search_name, tv_search_address, tv__search_distance, divide, tv_examine_type;
            private LinearLayout lly_search_phone, lly_search_gps, lly_search_share, lly_search, lly_select;
        }
    }

    //电话的popupwindow
    private void initPhonePopuWindow(String mobile) {

        LayoutInflater inflater = LayoutInflater.from(mActivity);
        View layout = inflater.inflate(R.layout.pop_phone, null);
        lly_pop_phone = (LinearLayout) layout.findViewById(R.id.lly_pop_phone);
        tv_pop_phone = (TextView) layout.findViewById(R.id.tv_pop_phone);
        tv_pop_cancel = (TextView) layout.findViewById(R.id.tv_pop_cancel);
        layout.invalidate();
        pop_phone = new PopupWindow(layout, ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        pop_phone.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {

            }
        });
        pop_phone.setBackgroundDrawable(new BitmapDrawable());
        pop_phone.setOutsideTouchable(true);
        pop_phone.setFocusable(true);
        tv_pop_phone.setText(mobile);
        lly_pop_phone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_DIAL);
                Uri data = Uri.parse("tel:" + tv_pop_phone.getText().toString());
                intent.setData(data);
                startActivity(intent);
                pop_phone.dismiss();
                pop_phone.setFocusable(false);
            }
        });

        tv_pop_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pop_phone.dismiss();
                pop_phone.setFocusable(false);
            }
        });

    }

    //审核的popupwindow
    private void initShowPop() {

        View contentview = LayoutInflater.from(mActivity).inflate(R.layout.pop_examine, null);
        pop_examine = new PopupWindow(contentview, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT, true);
        pop_examine.setTouchable(true);
        ColorDrawable dw = new ColorDrawable(0x00000000);
        //设置PopupWindow弹出窗体的背景
        pop_examine.setBackgroundDrawable(dw);
        pop_examine.setOutsideTouchable(true);
        pop_examine.setFocusable(true);


        pop_examine.setTouchInterceptor(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return false;
                // 这里如果返回true的话，touch事件将被拦截
                // 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
            }
        });
        pop_examine.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                WindowManager.LayoutParams lp = mActivity.getWindow().getAttributes();
                lp.alpha = 1;
                mActivity.getWindow().setAttributes(lp);
            }
        });


        TextView tv_pop_title = (TextView) contentview.findViewById(R.id.tv_pop_title);
        if (code == 1) {
            tv_pop_title.setText("确定审核通过");

        } else if (code == 2) {
            tv_pop_title.setText("确定关闭用户？");
        }
        TextView tv_pop_no = (TextView) contentview.findViewById(R.id.tv_pop_no);
        TextView tv_pop_yes = (TextView) contentview.findViewById(R.id.tv_pop_yes);

        tv_pop_no.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                pop_examine.dismiss();
            }
        });

        tv_pop_yes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (code == 1) {
                    //审核通过
                    UpdataStore("1");

                } else if (code == 2) {
                    //审核不通过
                    UpdataStore("2");

                }
            }
        });
    }

    public void routeplanToNavi(double jingdu, double weidu, BNRoutePlanNode.CoordinateType coType) {
        BNRoutePlanNode sNode = null;
        BNRoutePlanNode eNode = null;
        Log.e("url", "目的地址:经度==" + jingdu + " 纬度==" + weidu);

        switch (coType) {
            case GCJ02: {
                Log.e("ssss", "导航");
                sNode = new BNRoutePlanNode(Double.parseDouble(sharedPreferencesUtil.getJingdu()), Double.parseDouble(sharedPreferencesUtil.getWeidu()), "目前地址", null, coType);

                eNode = new BNRoutePlanNode(jingdu, weidu, "目的地", null, coType);
                Log.e("url", "sNode==" + sNode + "   eNode==" + eNode);
                Log.e("url", "当前地址:纬度==" + sharedPreferencesUtil.getJingdu() + " 经度==" + sharedPreferencesUtil.getWeidu());
                Log.e("url", "目的地址:经度==" + jingdu + " 纬度==" + weidu);
                break;
            }
//            case WGS84: {
//                sNode = new BNRoutePlanNode(116.300821, 40.050969,
//                        "百度大厦", null, coType);
//                eNode = new BNRoutePlanNode(116.397491, 39.908749,
//                        "北京天安门", null, coType);
//                break;
//            }
//            case BD09_MC: {
//                sNode = new BNRoutePlanNode(12947471, 4846474,
//                        "百度大厦", null, coType);
//                eNode = new BNRoutePlanNode(12958160, 4825947,
//                        "北京天安门", null, coType);
//                break;
//            }
            default:

        }
        if (sNode != null && eNode != null) {
            List<BNRoutePlanNode> list = new ArrayList<BNRoutePlanNode>();
            list.add(sNode);
            list.add(eNode);
            BaiduNaviManager.getInstance().launchNavigator(mActivity, list, 1, true, new DemoRoutePlanListener(sNode));
        }
    }

    public class DemoRoutePlanListener implements BaiduNaviManager.RoutePlanListener {

        private BNRoutePlanNode mBNRoutePlanNode = null;

        public DemoRoutePlanListener(BNRoutePlanNode node) {
            Log.e("url", "DemoRoutePlanListener");
            mBNRoutePlanNode = node;
            Log.e("url", "mBNRoutePlanNode==" + mBNRoutePlanNode);
        }

        @Override
        public void onJumpToNavigator() {
            Log.e("url", "onJumpToNavigator_BNDemoGuideActivity");
            Intent intent = new Intent(mActivity, BNDemoGuideActivity.class);
            Bundle bundle = new Bundle();
            bundle.putSerializable(ROUTE_PLAN_NODE, (BNRoutePlanNode) mBNRoutePlanNode);
            intent.putExtras(bundle);
            startActivity(intent);
        }

        @Override
        public void onRoutePlanFailed() {
            // TODO Auto-generated method stub
            Log.e("url", "onRoutePlanFailed");
        }

    }

    private void initNavi() {

        BNOuterTTSPlayerCallback ttsCallback = null;

        BaiduNaviManager.getInstance().init(mActivity, mSDCardPath, APP_FOLDER_NAME,
                new BaiduNaviManager.NaviInitListener() {
                    @Override
                    public void onAuthResult(int status, final String msg) {
                        if (0 == status) {
                            authinfo = "key校验成功!";
                            Log.e("ssss", "key校验成功");
                        } else {
                            authinfo = "key校验失败, " + msg;
                            Log.e("ssss", "key校验失败");
                        }
                        mActivity.runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
//                                Toast.makeText(mActivity, authinfo, Toast.LENGTH_LONG).show();
                                Log.e("ssss", "Map_authinfo==" + authinfo);
                            }
                        });

                    }

                    public void initSuccess() {
//                        Toast.makeText(mActivity, "百度导航引擎初始化成功", Toast.LENGTH_SHORT).show();
                        Log.e("ssss", "Map_百度导航引擎初始化成功");
                    }

                    public void initStart() {
//                        Toast.makeText(mActivity, "百度导航引擎初始化开始", Toast.LENGTH_SHORT).show();
                        Log.e("ssss", "Map_百度导航引擎初始化开始");
                    }

                    public void initFailed() {
//                        Toast.makeText(mActivity, "百度导航引擎初始化失败", Toast.LENGTH_SHORT).show();
                        Log.e("ssss", "Map_百度导航引擎初始化失败");
                    }
                }, null /*mTTSCallback*/);
    }

    private boolean initDirs() {
        mSDCardPath = getSdcardDir();
        if (mSDCardPath == null) {
            return false;
        }
        File f = new File(mSDCardPath, APP_FOLDER_NAME);
        if (!f.exists()) {
            try {
                f.mkdir();
            } catch (Exception e) {
                e.printStackTrace();
                return false;
            }
        }
        return true;
    }

    //分享
    private void showShare(String url) {
        ShareSDK.initSDK(mActivity);
        OnekeyShare oks = new OnekeyShare();
        //关闭sso授权
        oks.disableSSOWhenAuthorize();

        // title标题，印象笔记、邮箱、信息、微信、人人网和QQ空间等使用
        oks.setTitle("标题");
        // titleUrl是标题的网络链接，QQ和QQ空间等使用
        oks.setTitleUrl(url);
        // text是分享文本，所有平台都需要这个字段
        oks.setText("我是分享文本");
        // imagePath是图片的本地路径，Linked-In以外的平台都支持此参数
        //oks.setImagePath("/sdcard/test.jpg");//确保SDcard下面存在此张图片
        // url仅在微信（包括好友和朋友圈）中使用
        oks.setUrl(url);
        // comment是我对这条分享的评论，仅在人人网和QQ空间使用
        oks.setComment("我是测试评论文本");
        // site是分享此内容的网站名称，仅在QQ空间使用
        oks.setSite(getString(R.string.app_name));
        // siteUrl是分享此内容的网站地址，仅在QQ空间使用
        oks.setSiteUrl(url);

        // 启动分享GUI
        oks.show(mActivity);
    }
}
